package com.yjs.ppjokedemo.adapter;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.ListAdapter;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.yjs.ppjokedemo.bean.TextProduct;
import com.yjs.ppjokedemo.databinding.ItemSofaTextBinding;

public class TextListAdapter extends ListAdapter<TextProduct,TextListAdapter.TextViewHolder> {

    TextInterface mTextInterface;

    public TextListAdapter(TextInterface textInterface){
        super(TextProduct.itemCallback);
        this.mTextInterface = textInterface;
    }

    @Override
    public TextViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
        ItemSofaTextBinding itemSofaTextBinding = ItemSofaTextBinding.inflate(layoutInflater,parent,false);
        itemSofaTextBinding.setTextInterface(mTextInterface);
        return new TextViewHolder(itemSofaTextBinding);
    }

    @Override
    public void onBindViewHolder(@NonNull TextViewHolder holder, int position) {
        TextProduct textProduct = getItem(position);
        holder.mTextBinding.setTextProduct(textProduct);
        holder.mTextBinding.llText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("name",textProduct.getName());
                bundle.putString("ivTou",textProduct.getIvTou());
                bundle.putString("caption",textProduct.getCaption());

                ARouter.getInstance()
                        .build("/app/SofaTextDetailActivity")
                        .withBundle("dataBean",bundle)
                        .navigation(v.getContext());
            }
        });


    }

    static class TextViewHolder extends RecyclerView.ViewHolder{
        ItemSofaTextBinding mTextBinding;

        public TextViewHolder(ItemSofaTextBinding textBinding){
            super(textBinding.getRoot());
            this.mTextBinding = textBinding;
        }
    }

    public interface TextInterface{

    }
}
